package com.turbo.cloud.contract.web.webservice;

import com.turbo.cloud.contract.web.logic.TemplateLogic;
import com.turbo.cloud.contract.web.model.template.CtContractTemplateQO;
import com.turbo.cloud.contract.web.model.template.CtContractTemplateDO;
import com.turbo.cloud.contract.web.model.template.CtContractTemplateVO;
import com.turbo.cloud.core.api.R;
import com.turbo.cloud.core.api.Result;
import com.turbo.cloud.core.base.PageQuery;
import com.turbo.cloud.core.validated.InsertValidated;
import com.turbo.cloud.core.validated.UpdateValidated;
import jakarta.validation.constraints.NotBlank;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 合同模板表 前端控制器
 * </p>
 *
 * @author zhangluning
 * @since 2023-11-23
 */
@Slf4j
@RequiredArgsConstructor
@RestController
public class CtContractTemplateController {

    final TemplateLogic templateLogic;

    /**
     * 模糊查询合同模板分页列表
     *
     * @param pageQuery 分页查询实体
     * @return Page
     */
    @PostMapping(name = "模糊查询用户分页列表", value = "/webservice/template/queryContractTemplatePage")
    public Result<PageQuery<CtContractTemplateVO>> queryContractTemplatePage(@RequestBody PageQuery<CtContractTemplateQO> pageQuery) {
        PageQuery<CtContractTemplateVO> result = templateLogic.queryContractTemplatePage(pageQuery);
        return R.result(result);
    }

    /**
     * 新增合同模板
     *
     * @param ctContractTemplateDO 实体
     * @return
     */
    @PostMapping(name = "新增合同模板", value = "/webservice/template/createContractTemplate")
    public Result<Boolean> createRole(@RequestBody @Validated(InsertValidated.class) CtContractTemplateDO ctContractTemplateDO) {
        boolean result = templateLogic.createContractTemplate(ctContractTemplateDO);
        return R.result(result);
    }

    /**
     * 修改合同模板
     *
     * @param ctContractTemplateDO 实体
     * @return
     */
    @PostMapping(name = "修改合同模板", value = "/webservice/template/modifyContractTemplate")
    public Result<Boolean> modifyRole(@RequestBody @Validated(UpdateValidated.class) CtContractTemplateDO ctContractTemplateDO) {
        boolean result = templateLogic.modifyContractTemplate(ctContractTemplateDO);
        return R.result(result);
    }

    /**
     * 开启、关闭合同模板有效状态
     *
     * @param id 合同模板ID
     * @return
     */
    @GetMapping(name = "开启、关闭合同模板有效状态", value = "/webservice/template/enabledContractTemplateStateById")
    public Result<Boolean> enabledContractTemplateStateById(@RequestParam @NotBlank(message = "合同模板ID不能为空") String id) {
        boolean result = templateLogic.enabledContractTemplateStateById(id);
        return R.result(result);
    }

    /**
     * 删除合同模板
     *
     * @param id 合同模板ID
     * @return
     */
    @GetMapping(name = "删除合同模板", value = "/webservice/template/removeContractTemplateById")
    public Result<Boolean> removeContractTemplateById(@RequestParam @NotBlank(message = "合同模板ID不能为空") String id) {
        boolean result = templateLogic.removeContractTemplateById(id);
        return R.result(result);
    }
}
